package com.study.contoller;

import com.study.R;
import com.study.entity.Role;
import com.study.entity.School;
import com.study.mapper.RoleMapper;
import com.study.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

/**
 * @author:zt
 * @createDate: 2022/6/18
 */

@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("selects")
    public R selects() {
        return R.ok().setData(roleService.selects());
    }

    @DeleteMapping("{id}")
    public R del(@PathVariable Integer id) {
        try {
            roleService.deleteByPrimaryKey(id);
            return R.ok();
        } catch (Exception e) {
            return R.error().setMessage("删除失败");
        }
    }
    @PostMapping("add")
    public R insert(@RequestBody Role role) {
        try {
            roleService.insertSelective(role);
            return R.ok();
        } catch (Exception e) {
            return R.error().setMessage("添加失败");
        }
    }
    /**
     * 修改
     */
    @PutMapping
    public R updateKey(@RequestBody Role role){
        try{
            roleService.updateByPrimaryKeySelective(role);
            return R.ok();
        }catch (Exception e){
            return R.error().setMessage("修改失败");
        }
    }
}
